package com.flyu.myThread.Sleep;


// 模拟抢票
public class MySleep implements Runnable{
    private int ticketsNum = 10;
    @Override
    public void run() {
        while (true){
            if (ticketsNum <= 0){
                break;
            }
            // 模拟延时
            try {
                Thread.sleep(1000);

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"拿到了第" + ticketsNum-- + "张票");
        }
    }

    public static void main(String[] args) {
        MySleep mySleep = new MySleep();

        new Thread(mySleep, "小明").start();
        new Thread(mySleep, "小红").start();
        new Thread(mySleep, "小张").start();
    }
}
